//
//  YJQSportTrakingLineModel.m
//  GoodLuck
//
//  Created by 杨瑞 on 16/12/14.
//  Copyright © 2016年 杨瑞. All rights reserved.
//

#import "YJQSportTrakingLineModel.h"

@implementation YJQSportTrakingLineModel

- (instancetype)initWithStartLocation:(CLLocation *)startLocation endLocation:(CLLocation *)endLocation
{
    self = [super init];
    if (self) {
        _startLocation = startLocation;
        _endLocation = endLocation;
    }
    return self;
}

-(MAPolyline *)polyline {
    CLLocationCoordinate2D coords[2];
    coords[0] = _startLocation.coordinate;
    coords[1] = _endLocation.coordinate;
//    NSLog(@"%f",self.speed);
    NSLog(@"速度 %f, 时间 %f,距离 %f",self.speed,self.time,self.distance);
    //设置放大因子
    CGFloat scale = 8;
    CGFloat red = scale * self.speed / 255.0;
    UIColor *color = [UIColor colorWithRed:red green:1 blue:0 alpha:1];
    return [YJQSportPolyline polylineWithCoordinates:coords count:2 color:color];
}

/**
 平均速度
 */
-(CLLocationSpeed)speed {
    return (_startLocation.speed + _endLocation.speed) * 0.5 * 3.6;
}
-(NSTimeInterval)time {
    return [_endLocation.timestamp timeIntervalSinceDate:_startLocation.timestamp];
}
-(CLLocationDistance)distance {
    return [_endLocation distanceFromLocation:_startLocation] * 0.001;
}
@end
